//
//  BaseTuijianCell.m
//  网易新闻
//
//  Created by dllo on 15/10/7.
//  Copyright (c) 2015年 Lx. All rights reserved.
//

#import "BaseTuijianCell.h"
#import "SDWebImage/UIImageView+WebCache.h"
#import "Settings.h"
@interface BaseTuijianCell()

@end
@implementation BaseTuijianCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundColor = [[Settings shareSettings]color:WhiteToGray];
        self.selectedBackgroundView = [[[UIView alloc] initWithFrame:self.frame] autorelease];
        self.selectedBackgroundView.backgroundColor = [[Settings shareSettings]color:GrayToBlack];
        [self sendSubviewToBack:self.selectedBackgroundView];
        self.background.backgroundColor = [[Settings shareSettings]color:WhiteToLightGray];
        
        self.img = [[UIImageView alloc]init];
        self.img.backgroundColor = [UIColor lightGrayColor];
        [self.background addSubview:self.img];
        [self.img release];
        
        self.title = [[UILabel alloc]init];
        self.title.textColor = [[Settings shareSettings]color:BlackToWhite];
        self.title.numberOfLines = 0;
        [self.title sizeToFit];
        [self.background addSubview:self.title];
        [self.title release];
        
        self.source = [[UILabel alloc]init];
        self.source.textColor = [UIColor lightGrayColor];
        self.source.font = [UIFont systemFontOfSize:10];
        [self.background addSubview:self.source];
        [self.source release];
        
        self.line = [[UILabel alloc]init];
        self.line.backgroundColor = [UIColor lightGrayColor];
        [self.background addSubview:self.line];
        [self.line release];
        
        [self notificationHandle];
    }
    return self;
}

- (void)layoutSubviews{
    [super layoutSubviews];
    self.background.frame = CGRectMake(12, 12, 350, 295);
    self.img.frame = CGRectMake(0, 0, 350, 195);
    self.title.frame = CGRectMake(15, 205, 320, 45);
    self.source.frame = CGRectMake(15, 265, 100, 20);
    self.line.frame = CGRectMake(15, 255, 320, 1);
}

- (void)setOtherMod:(TuijianModel *)mod{
    self.height = 310;
    [self.img sd_setImageWithURL:mod.img placeholderImage:nil];
    self.title.text = mod.title;
    self.source.text = mod.source;
}

- (void)notificationHandle{
    [[NSNotificationCenter defaultCenter]addObserverForName:@"changeBackgroundColor" object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *note) {
        self.backgroundColor = [[Settings shareSettings]color:WhiteToGray];
        self.background.backgroundColor = [[Settings shareSettings]color:WhiteToLightGray];
        self.selectedBackgroundView.backgroundColor = [[Settings shareSettings]color:GrayToBlack];
        self.title.textColor = [[Settings shareSettings]color:BlackToWhite];
    }];
}

- (void)dealloc{
    [_img release];
    [_title release];
    [_source release];
    [_line release];
    [super dealloc];
}

- (void)awakeFromNib {
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
}

@end
